<?php
/**
 * Created by PhpStorm.
 * User: 36980
 * Date: 2017/08/14
 * Time: 17:36
 */

namespace Home\Controller;


use Think\Controller;

class ExtensionController extends Controller
{
    /**
     * 跳转展示页面
     */
    public function index(){
		
        $xxid = trim(I('xxid'));
	

        $where = array();
        $where['spare2'] = $xxid;
		
        $model = M('classburl')->where($where)->find();
		
        $url = $model['cburl'];
        $uname = $model['cbname'];
        $id = $model['cbid'];

        if(!strstr($url,"http://")){
            $url = "http://".$url;
        }



        $this->assign("uname",$uname);
        $this->assign('url',$url);
        $this->display();
    }

    /**
     * 跳转
     */
    public function jump(){
      //  $aa = I('jump');
        //用get请求获取跳转所需要的参数id
        $id=$_GET['jump'];
        //根据id查询
        $model = M('classburl')->where("cbId = $id")->find();

        $url = $model['cburl'];
        $uname = $model['cbname'];
        if(!strstr($url,"http://")){
            $url = "http://".$url;
        }
        $analysis = M('Classcurl')->where("ccState = 0")->select();

        if(empty($analysis)){
           
        }
        $anal = "";
        foreach($analysis as $k=>$v){
            if($_SERVER['HTTP_HOST'] == $v['ccanalysis']){
                continue;
            }else{
                $anal = $v['ccanalysis'];
                break;
            }

        }

        $this->assign("uname",$uname);
        $this->assign('url',$url);
        // $this->display("Extension/index");
        redirect("http://$anal/Extension/index/jump/$id");
    }



    public function index2()
    {
        $xxid = trim(I('xxid'));
	

        $where = array();
        $where['spare2'] = $xxid;
		
        $model = M('classburl')->where($where)->find();
		
        $url = $model['cburl'];
        $uname = $model['cbname'];
        $id = $model['cbid'];

        if(!strstr($url,"http://")){
            $url = "http://".$url;
        }
        $analysis = M('Classcurl')->limit(1)->where("ccState = 0")->order('rand()')->find();
			
        if(empty($analysis)){
            redirect(U('Login/nopage'));
            exit;
        }
            
            if(!$analysis){
                $anal = $_SERVER['HTTP_HOST'];
            }else{
                $anal = $analysis['ccanalysis'];
            }

        $this->assign("uname",$uname);
        $this->assign('url',$url);
        // $this->display("Extension/index");
        redirect("http://$anal/e/$xxid");
    }


    public function jump1(){
        $xxid = trim(I('xxid'));
        $arr = M('Articles');
        $where['arId'] = $xxid;
        $arr = $arr->where($where)->find();
        M('Articles')->where("arId = $xxid")->setInc('upnum');
        if(!strstr( $arr['arandroid'],"http://")) {

            $arr['arandroid'] = "http://" . $arr['arandroid'];

        }
        if(!strstr( $arr['arios'],"http://")) {

            $arr['arios'] = "http://" . $arr['arios'];

        }
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')) {
            redirect($arr['arios']);
        } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'Android')) {
            redirect($arr['arandroid']);
        }else{

            if($arr['arios']){
                redirect($arr['arios']);
            }else if($arr['arandroid']){
                redirect($arr['arandroid']);
            }else{
                redirect(U('Login/nopage'));
            }

        }
    }
}